import json
import os

from myapp import models
from myapp.utils.wordCloudPicture import createWordCloudImage, createWordCloudImage2


def getPageData():
    titleText = ''
    titleCloudResult = False
    tagText = ''
    tagCloudResult = False

    jobs = models.JobInfo.objects.all()
    for j in jobs:
        titleText += j.title

        if j.companyTags != '无':
            tags = json.loads(j.companyTags)
            for t in tags:
                tagText += t

    path = os.getcwd()
    stopWordFile = path + '/myapp/utils/stopwords.txt'
    if titleText:
        makeImage = path + '/static/clouds/source/cloud.png'
        saveImage = path + '/static/clouds/titleCloud.png'
        tagCloudResult = createWordCloudImage2(tagText, makeImage, saveImage, stopWordFile)

    if tagText:
        makeImage = path + '/static/clouds/source/gift.jpg'
        saveImage = path + '/static/clouds/companyTagsCloud.png'
        tagCloudResult = createWordCloudImage2(tagText, makeImage, saveImage, stopWordFile)

    return titleCloudResult, tagCloudResult
